Update MailerAssertionsTrait.php: Adding Mailpit#204
Update MailerAssertionsTrait.php: Adding Mailpit#204TavoNiievez merged 4 commits intoCodeception:mainfrom
Conversation
I will add a link to Mailpit, as soon as Codeception/codeception.github.com#880 is merged.
| * If your app performs an HTTP redirect after sending the email, you need to suppress it using [stopFollowingRedirects()](#stopFollowingRedirects) first. | ||
| * | ||
| * Limitation: | ||
| * If your mail is sent in a Symfony console command and you start that command in your test with [$I->runShellCommand()](https://codeception.com/docs/modules/Cli#runShellCommand), |
There was a problem hiding this comment.
please clarify if this problem is also present in runSymfonyConsoleCommand, because when reading it seems to be exclusive of runShellCommand.
There was a problem hiding this comment.
I'm not sure if I tried. But the mail assertions are working by looking at the web debug toolbar, aren't they?
There was a problem hiding this comment.
I didn't try runSymfonyConsoleCommand(). Is there a way to pipe input to the command?
Right now, I'm doing:
$I->runShellCommand('printf "foobar" | php bin/console app:my_command --env=test');There was a problem hiding this comment.
@ThomasLandauer yes, you can use the third parameter $consoleInputs for that. So the equivalent to the above would be
$I->runSymfonyConsoleCommand('app:my_command', ['--env' => 'test'], ['foobar']);There was a problem hiding this comment.
Hm, then the test executions hangs at this line - looks like the console is waiting for something. I didn't look into it further - are you sure that this works?
There was a problem hiding this comment.
@ThomasLandauer I tested it before writing that comment just to be sure, so yes, it does work in general. Maybe we're talking about different things, so I created Codeception/symfony-module-tests#28 to demonstrate what I'm talking about.
There was a problem hiding this comment.
The test is a cool idea!
My command doesn't ask questions (i.e. doesn't wait for input), it reads input from STDIN:
$fread = fread(STDIN, $length);There was a problem hiding this comment.
@ThomasLandauer oh, I see. I didn't have such a use case yet, so I don't know, but the console input parameter might indeed not work with STDIN then.
| * Limitation: | ||
| * If your mail is sent in a Symfony console command and you start that command in your test with [$I->runShellCommand()](https://codeception.com/docs/modules/Cli#runShellCommand), | ||
| * Codeception will not notice it. | ||
| * As a more professional alternative, we recommend Mailpit, wchich also lets you test the content of the mail. |
There was a problem hiding this comment.
is not clear why it is more 'professional'.
Please explain what Mailpit is and how it works as an alternative to what within Codeception exactly, in what specific scenario you are going to recommend its use and how to integrate it into the functional testing workflow with this module.
by the way, there is a tiny typo in 'wchich'.
| * If your app performs an HTTP redirect after sending the email, you need to suppress it using [stopFollowingRedirects()](#stopFollowingRedirects) first. | ||
| * | ||
| * Limitation: | ||
| * If your mail is sent in a Symfony console command and you start that command in your test with [$I->runShellCommand()](https://codeception.com/docs/modules/Cli#runShellCommand), |
There was a problem hiding this comment.
I'm not sure if I tried. But the mail assertions are working by looking at the web debug toolbar, aren't they?
| * Limitation: | ||
| * If your mail is sent in a Symfony console command and you start that command in your test with [$I->runShellCommand()](https://codeception.com/docs/modules/Cli#runShellCommand), | ||
| * Codeception will not notice it. | ||
| * As a more professional alternative, we recommend Mailpit, wchich also lets you test the content of the mail. |
There was a problem hiding this comment.
Please merge Codeception/codeception.github.com#880 first, so I can add a link to it here. I don't think adding all features of Mailpit here is a good idea, cause nobody will ever update that :-)
IMO the main advantage is that you can assert the mail's content. And sooner or later most people probably want a mailcatching solution anyway (not just for testing, but also for development), so I'm figuring it's a good idea to tell them early...
| * If your app performs an HTTP redirect after sending the email, you need to suppress it using [stopFollowingRedirects()](#stopFollowingRedirects) first. | ||
| * | ||
| * Limitation: | ||
| * If your mail is sent in a Symfony console command and you start that command in your test with [$I->runShellCommand()](https://codeception.com/docs/modules/Cli#runShellCommand), |
There was a problem hiding this comment.
I didn't try runSymfonyConsoleCommand(). Is there a way to pipe input to the command?
Right now, I'm doing:
$I->runShellCommand('printf "foobar" | php bin/console app:my_command --env=test');|
Looks like I cannot link to Mailpit's entry at https://codeception.com/addons directly? |
I will add a link to Mailpit, as soon as Codeception/codeception.github.com#880 is merged.